package com.lottery.game.runner.v2;

import com.lottery.game.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import lombok.extern.slf4j.Slf4j;

/**
 * 更新机器人列表类 10秒扫描一次数据库
 * @author Jake
 *
 */
@Slf4j
@Component
public class RobotThreadRunner implements ApplicationRunner {

//	private final long INTERVAL = 10 * 1000l;  //每隔10秒运行
//	private final long INIT_DELAY = 5 * 1000l; //初始延迟5秒启动

	@Autowired
	private RobotExecutor excutor;

//	@Scheduled(fixedDelay = INTERVAL, initialDelay = INIT_DELAY)
//	public void run() {
//		log.info("当前时间：{}，主线程更新机器人启动。。", DateUtils.getNowDateString());
//		ExecutorService exec = Executors.newCachedThreadPool();
//		exec.execute(excutor);
//	}

	@Override
	public void run(ApplicationArguments args) throws Exception {
		log.info("当前时间：{}，主线程更新机器人启动。。", DateUtils.getNowDateString());
		ExecutorService exec = Executors.newCachedThreadPool();
		exec.execute(excutor);
	}

}
